<? 
	include('base.php');
	User::protect();
	include_class('band_members');
	$bm = BandMember::get($_GET['id']);
	
	switch($_GET['task']) {
		case 'update':
			$res = $bm->update($_POST);
			if (!db::isError($res)) {
				header('Location: band_member_edit.php?id=' . $_GET['id']);
			}
			break;
		case 'deactivate':
			$res = $bm->deactivate();
			if (!db::isError($res)) {
				header('Location: band_member_edit.php?id=' . $_GET['id']);
			}
			break;
		case 'activate':
			$res = $bm->activate();
			if (!db::isError($res)) {
				header('Location: band_member_edit.php?id=' . $_GET['id']);
			}
			break;
		case 'delete':
			$res = $bm->remove();
			if (!db::isError($res)) {
				header('Location: band_members.php');
			}
			break;
	}
	
	$calendar = true;
	$section = 'band_members';
	$editors = array('equipment', 'influences','bio');
	$page_title = 'Edit Band Member';
	include('layout/header.php');
?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_members.php">Band Members&nbsp;&#62;</a>&nbsp;View/Edit Band Member
</div>

<? if (db::isError($bm)) {
	
	$bm->outputDialog('Return to Band Members','band_members.php');

} else { 

	if ($res) { // it's an error
		if (db::isError($res)) {
			$res->outputList();
		}
	}

	$bmu = $bm->getUserObject();
	$email = ($_GET['task'] == 'update') ? $_POST['email'] : $bmu->getEmailAddress();
	$birthdate = ($_GET['task'] == 'update') ? $_POST['birthdate'] : $bmu->getBirthDate();
	$lastname = ($_GET['task'] == 'update') ? $_POST['lastname'] : $bmu->getLastName();
	$firstname = ($_GET['task'] == 'update') ? $_POST['firstname'] : $bmu->getFirstName();
	$equipment = ($_GET['task'] == 'update') ? $_POST['equipment'] : $bm->getEquipment();
	$bio = ($_GET['task'] == 'update') ? $_POST['bio'] : $bm->getBio();
	$influences = ($_GET['task'] == 'update') ? $_POST['influences'] : $bm->getInfluences();
	$role = ($_GET['task'] == 'update') ? $_POST['role'] : $bm->getRole();
	
	if ($_GET['id'] && ($_GET['task'] == 'edit' || $_GET['task'] == 'update') && $bm->canEdit()) { ?>
	
		<h1>edit band member:</h1>
		<div class="inset">
		<form id="edit_entry" action="<?=$PHP_SELF?>?task=update&amp;id=<?=$_GET['id']?>" method="post">
		<table border="0" cellspacing="0" cellpadding="0" class="edit-form">
		<tr>
			<td width="50%"><strong>Username</strong><br/><?=$bmu->getUserName()?></td>
			<td width="50%"><strong>Email Address</strong><br/><input type="text" name="email" value="<?=$email?>" class="text"></td>
		</tr>
		<tr>
			<td><strong>Password</strong><br/><input type="password" name="password" value="" class="text" /></td>
			<td><strong>Password (Confirm)</strong><br/><input type="password" name="password_confirm" value="" class="text" /></td>
		</tr>
		<tr>
			<td colspan="2">Leave the password blank for it to remain unchanged.</td>
		</tr>
		</table>
		<table border="0" cellspacing="0" cellpadding="0" class="edit-form">
				<tr>
			<td><strong>Date of Birth (<a style="vertical-align: middle" href="javascript:void(0)" onclick="popUpCalendar(this, document.getElementById('date'), '<?=DATE_JS_CALENDAR?>')">Calendar</a>)</strong><br/>
				<input type="text" name="birthdate" id="date" value="<?=$birthdate?>" class="text"></td>
			<td><strong>Last&nbsp;Name:<br/><input type="text" name="lastname" value="<?=$lastname?>" class="text"></td>
			<td><strong>First Name</strong><br/><input type="text" name="firstname" value="<?=$firstname?>" class="text"></td>
		</tr>
		</table>
		<div class="edit-form">
			<strong>Role</strong><br/><input type="text" class="text" value="<?=$role?>" name="role" />
		</div>
		<div class="edit-form">
			<strong>Equipment</strong><br/><textarea class="mid" id="equipment" name="equipment"><?=$equipment?></textarea>
		</div>
		<div class="edit-form">
			<strong><strong>Influences</strong><br/><textarea id="influences" class="mid" name="influences"><?=$influences?></textarea>
		</div>
		<div class="edit-form">
			<strong>Bio</strong><br/><textarea class="full" id="bio" name="bio"><?=$bio?></textarea>
		</div>
		
		<div class="edit-form">
			<input type="submit" value="Update Member" name="submit" class="button">
			<input type="submit" value="Exit Without Updating" name="preview" onclick="location.href='<?=$PHP_SELF?>?id=<?=$bm->getID()?>'; return false" class="button">
		</div>
		
	
	<? } else { ?>

		<h1>view band member:</h1>
		<div class="inset">
		
		<?
		
		$bmu = $bm->getUserObject();
		
		?>
		<h2><?=$bmu->getFirstName()?> <?=$bmu->getLastName()?></h2>
		<span class="small">
			Status: <? if ($bm->isActive()) { ?><b>Active</b><? } else { ?><b>Inactive</b><? } ?><? if ($bmu->getBirthDate() != '0000-00-00') { ?><span class="padded">|</span>DOB: <?=$bmu->getBirthDate()?><? } ?><? if ($bmu->getEmailAddress()) { ?><span class="padded">|</span><a href="mailto:<?=$bmu->getEmailAddress()?>"><?=$bmu->getEmailAddress()?></a><? } ?>
		</span>
		<br><br>
		<? if ($bm->getRole()) { ?>
			<b>Role:</b><br>
			<?=$bm->getRole()?><br><br>
		<? } ?>
		<? if ($bm->getEquipment()) { ?>
			<b>Equipment:</b><br>
			<?=$bm->getEquipment()?><br><br>
		<? } ?>
		<? if ($bm->getInfluences()) { ?>
			<b>Influences:</b><br>
			<?=$bm->getInfluences()?><br><br>
		<? } ?>
		<? if ($bm->getBio()) { ?>
			<b>Bio:</b><br>
			<?=$bm->getBio()?><br><br>
		<? } ?>
		<form name="entry_status" method="get">
			<? if ($bm->canEdit()) { ?><input type="submit" name="" value="Edit" onclick="location.href='<?=$PHP_SELF?>?task=edit&id=<?=$_GET['id']?>';return false" class="button"><? } else if ($_SESSION['user_id'] == $_GET['id']) { ?><input type="submit" name="" value="Edit Information" onclick="location.href='<?=$PHP_SELF?>?task=edit&id=<?=$_GET['id']?>';return false" class="button"><? } ?>
			<input type="button" name="" value="Photos" onclick="location.href='band_member_media.php?id=<?=$_GET['id']?>&type=photos';return false" class="button">
			<input type="button" name="" value="Audio/Video" onclick="location.href='band_member_media.php?id=<?=$_GET['id']?>&type=av';return false" class="button">
			
			<? if (User::isAdmin()) { ?>
				<? if ($bm->isActive()) { ?><input type="submit" name="" value="Deactivate" onclick="location.href='<?=$PHP_SELF?>?task=deactivate&id=<?=$_GET['id']?>';return false" class="button"><? } else { ?><input type="submit" name="" value="Activate" onclick="location.href='<?=$PHP_SELF?>?task=activate&id=<?=$_GET['id']?>';return false" class="button"><? } ?>
				<input type="submit" value="Delete" name="" onclick="if (confirm('Are you sure you wish to delete this band member?\rDoing so may compromise some release information.\rWhenever possible, deactivate rather than delete.')) { location.href='<?=$PHP_SELF?>?task=delete&id=<?=$_GET['id']?>'};return false" class="button">
			<? } ?>
			<input type="submit" value="Return to Band Members" name="" onclick="location.href='band_members.php'; return false" class="button">
		</form>
		
		</div>
	<? } ?>

	</div>
<? } ?>

<? include('layout/footer.php'); ?>
